$('document').ready(function() {
	loadOs();loadCat();
	$('#os').change(function() {
		loadOsv($(this).val());
		loadCompatible($(this).val());
	});
});
function loadOs() {
	var xmlhttp = new XMLHttpRequest();
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var getData = $.parseJSON(xmlhttp.responseText);
			var result = '<option value="0">Chọn hệ đều hành</option>';
			$.each(getData, function(key, obj) {
				result += '<option value=' + obj.os_id + '>' + obj.os_name
						+ '</option>';
			});
			document.getElementById("os").innerHTML = result;
		}
	};
	xmlhttp.open("GET", "http://localhost/kidplay/developer/app/getos", true);
	xmlhttp.send();
}
function loadCat() {
	var xmlhttp = new XMLHttpRequest();
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var getData = $.parseJSON(xmlhttp.responseText);
			var result = '<option value="0">Chọn danh mục</option>';
			$.each(getData, function(key, obj) {
				result += '<option value=' + obj.cat_id + '>' + obj.cat_name
						+ '</option>';
			});
			document.getElementById("cat").innerHTML = result;
		}
	};
	xmlhttp.open("GET", "http://localhost/kidplay/developer/app/getcat", true);
	xmlhttp.send();
}
function loadOsv(id) {
	var xmlhttp = new XMLHttpRequest();
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var getData = $.parseJSON(xmlhttp.responseText);
			var result = '';
			$.each(getData, function(key, obj) {
				result += '<option value=' + obj.osv_id + '>' + obj.osv_name
						+ '</option>';
			});
			document.getElementById("osv").innerHTML = result;
		}
	};
	xmlhttp.open("GET", "http://localhost/kidplay/developer/app/getosv?id="
			+ id, true);
	xmlhttp.send();
}

function loadCompatible(id) {
	var xmlhttp = new XMLHttpRequest();
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var getData = $.parseJSON(xmlhttp.responseText);
			var result = '';
			$.each(getData, function(key, obj) {
				result += '<option value=' + obj.cp_id + '>' + obj.cp_name
						+ '</option>';
			});
			document.getElementById("compatible").innerHTML = result;
		}
	};
	xmlhttp.open("GET",
			"http://localhost/kidplay/developer/app/getcompatible?id=" + id,
			true);
	xmlhttp.send();
}
